import math,operator

def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

class Fraction:
    def __init__(self,numerator,denominator):
        """
        denominator shoud always be positive.
        """
        if denominator == 0:
            raise ValueError("denominator can't be zero")
        if numerator < 0 and denominator < 0 :
            numerator,denominator = -numerator,-denominator
        elif numerator < 0 or denominator <0 :
            numerator,denominator = -abs(numerator),abs(denominator)

        reduction = gcd(numerator,denominator)
        self.numerator,self.denominator = numerator/reduction,denominator/reduction

    def __add__(self,other):
        """
        a/b + c/d = (ad + bc) / bd
        """
        return Fraction(self.numerator*other.denominator+other.numerator*self.denominator,
                        self.denominator*other.denominator)

    def __sub__(self,other):
        """
        a/b - c/d = (ad - bc) / bd
        """
        return Fraction(self.numerator*other.denominator-other.numerator*self.denominator,
                        self.denominator*other.denominator)

    def __mul__(self,other):
        """
        a/b * c/d = (b*d)/(a*c)
        """
        return Fraction(self.numerator*other.numerator,self.denominator*other.denominator)

    def __div__(self,other):
        """
        (a/b) / (c/d) = (a*c)/(b*d)
        """
        return Fraction(self.numerator*other.denominator,other.numerator*self.denominator)

    def __neg__(self):
        """
        -(a/b) = -a / b
        """
        return Fraction(-self.numerator,self.denominator)

    def __int__(self):
        """
        int(a/b) = (a//b)
        """
        return self.numerator//self.denominator

    def __invert__(self):
        """
        ~(a/b) = b/a
        """
        return Fraction(self.denominator,self.numerator)
    
    def __lt__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) < other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)<0)

    def __le__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) <= other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)<=0)

    def __eq__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) == other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)==0)

    def __ne__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) != other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)!=0)

    def __gt__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) > other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)>0)

    def __ge__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) >= other

        return ((self.numerator*other.denominator - other.numerator*other.denominator)>=0)

    def __cmp__(self,other):
        if not isinstance(other,self.__class__):
            return (float(self.numerator)/self.denominator) - other

        return (self.numerator*other.denominator - other.numerator*other.denominator)

    def __nonzero__(self):
        return self.numerator!=0
    
    def __hash__(self):
        return (self.numerator*13+self.denominator)*29

    def __abs__(self):
        return Fraction(abs(self.numerator),abs(self.denominator))

    def __repr__(self):
        return "%d/%d"%(self.numerator,self.denominator)

